package com.hula.onion.book.server.spider.platforms.lidecaifu;

import com.hula.onion.book.server.common.LoginForm;
import com.hula.onion.book.server.utils.RegexParserUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:礼德财富
 * Create Date:2018/1/17 19:49
 *
 * @author shan
 * @version 1.0
 */
@Component
public class LiDeCaiFuSpiderHelper {

    /**
     * 组装请求参数
     *
     * @param form
     * @return
     */
    public Map<String, Object> installRequestParams(LoginForm form, String publicKey) throws Exception {

        Map<String, Object> map = new HashMap<>(4);

        map.put("username", form.getUserName());
        map.put("password", form.getPassword());
        map.put("presite", "https://www.leadercf.com/index");
        map.put("ci_csrf_token", "");
        return map;

    }

    /**
     * 解析账户余额
     *
     * @param html
     * @return
     */
    public String parseAccountBalance(String html) {
        String beginRegex = "<p>账户余额（元）</p> <span>";
        String endRegex = "</span>";
        String result = new RegexParserUtils(beginRegex, endRegex, html, RegexParserUtils.TEXTTEGEX).getText();

        return result;
    }

    /**
     * 解析错误信息
     *
     * @param html
     * @return
     */
    public String parsErrorMessage(String html) {
        String beginRegex = "<head><title>";
        String endRegex = "</title></head>";
        String result = new RegexParserUtils(beginRegex, endRegex, html, RegexParserUtils.TEXTTEGEX).getText();
        if(null==result){
            result="礼德财富登录账号或密码错误！";
        }

        return result;
    }

}
